package com.black.knight.chess.components;

import java.io.IOException;
import java.io.InputStream;

import android.app.Dialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.view.Window;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.black.knight.chess.R;
import com.black.knight.chess.model.SahModel;

public class CustomizeLoadingDialog extends Dialog {
	
	private String message;
	
	public CustomizeLoadingDialog(Context context, String message) {
		super(context);

		LayoutInflater inflater = SahModel.context.getLayoutInflater();
		View layout = inflater.inflate(R.layout.thinking,
				(ViewGroup) SahModel.context
						.findViewById(R.id.toast_layout_root));
		TextView text = (TextView) layout.findViewById(R.id.text);
		text.setText(message);
		
		InputStream stream = null;
        try {
            stream = SahModel.context.getAssets().open("thinking.gif");
        } catch (IOException e) {
        	e.printStackTrace();
        }
        
        GifMovieView view = new GifMovieView(context, stream);
        
		LinearLayout image = (LinearLayout) layout.findViewById(R.id.image);

		image.addView(view);

		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(layout, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
		
		View layout = findViewById(R.id.toast_layout_root);
		
		TextView text = (TextView) layout.findViewById(R.id.text);
		text.setText(message);
	}
}